package com.example.demo.controller;

import com.example.demo.pojo.PageResult;
import com.example.demo.pojo.Reincarnationlog;
import com.example.demo.pojo.Result;
import com.example.demo.service.Impl.ReincarnationlogServiceImpl;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class ReincarnationlogController {
    @Autowired
    private ReincarnationlogServiceImpl reincarnationlogService;
    //轮回数据列表
    @GetMapping("/reincarnationlist")
    public Result ReincarnationlogQuery(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer limit,
                                                        Reincarnationlog reincarnationlog){
        PageInfo list = reincarnationlogService.ReincarnationlogQuery(page,limit,reincarnationlog);
        return PageResult.success03(list.getList(), (int) list.getTotal());
    }
    //轮回数据添加
    @PostMapping("/reincarnationadd")
    public Result ReincarnationlogAdd(@RequestBody Reincarnationlog reincarnationlog){
        String s = reincarnationlogService.ReincarnationlogAdd(reincarnationlog);
        if(s.equals("添加成功")){
            return Result.success(s);
        }
        return Result.error(s);
    }
    //轮回数据修改
    @PutMapping("/reincarnationedit")
    public Result ReincarnationlogUpdate(@RequestBody Reincarnationlog reincarnationlog){
        reincarnationlogService.ReincarnationlogUpdate(reincarnationlog);
        return Result.success("修改成功");
    }
    //轮回数据删除
    @DeleteMapping("/reincarnationdel")
    public Result ReincarnationlogDelete(Integer id){
        reincarnationlogService.ReincarnationlogDelete(id);
        return Result.success("删除成功");
    }
}
